package com.yunxun.coinmessage.dao;


import com.yunxun.coinmessage.entity.PushList;
import com.yunxun.coinmessage.sqlvo.PushListVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface PushListDao {

//    private int program_id;
//    private int uid;
//    private int con_id;
//    private Long rank;
//    private Long come_timestamp;
//    private String program_name;
//    private String uname;
//    private String con_title;
    @Insert("insert into pushlist(program_id,uid,con_id,con_title,come_timestamp,rank,program_name,uname)values(#{program_id},#{uid},#{con_id},#{con_title},#{come_timestamp},#{rank},#{program_name},#{uname})")
    int addPushItem(PushListVO pushListVO);
    @Select("select * from pushlist group by con_id order by push_id desc limit #{start},#{limit}")
    List<PushList> queryAllPushList(@Param("start")int start,@Param("limit")int limit);

    /**
     * 查询某篇资讯推送成功的条目，即查询推送成功的用户
     * @param con_id
     * @param con_id
     * @param start
     * @param limit
     * @return
     */
    @Select("select * from pushlist where con_id=#{con_id} and status=1 limit #{start},#{limit}")
    List<PushList> querySuccessUser(@Param("con_id")int con_id,@Param("start")int start,@Param("limit")int limit);

    /**
     * 查询某篇资讯推送失败的条目，即查询推送失败的用户
     * @param con_id
     * @param start
     * @param limit
     * @return
     */
    @Select("select * from pushlist where con_id=#{con_id} and status=3 limit #{start},#{limit}")
    List<PushList> queryfailureUser(@Param("con_id")int con_id, @Param("start")int start, @Param("limit")int limit);

    /**
     * 查询某篇资讯推送成功的总计
     * @param con_id
     * @return
     */
    @Select("select count(*) from pushlist where con_id=#{con_id} and status=1 ")
    int querySuccessTotal(@Param("con_id")int con_id);

    /**
     * 查询某篇资讯推送失败的总计
     * @param con_id
     * @return
     */
    @Select("select count(*) from pushlist where con_id=#{con_id} and status=3 ")
    int  queryfailureTotal(@Param("con_id")int con_id);


    /**
     * 点击一键推送将排序字段设为0，即可在推送列表中置顶
     * @param con_id
     * @return
     */
   @Update("update pushlist set rank=0 where con_id=#{con_id}")
    int updateRank(int con_id);
    /**
     * 点击某一用户手动键推送将排序字段设为0，即可在推送列表中置顶
     * @param con_id
     * @return
     */
    @Update("update pushlist set rank=0 where con_id=#{con_id} and uid=#{uid}")
    int updateRankByUser(@Param("con_id") int con_id,@Param("uid")int uid);

    /**
     * 查询要推送的资讯总数
     * @return
     */
    @Select("SELECT COUNT(`con_id`) from(SELECT `con_id` FROM `pushlist` GROUP BY `con_id`) as a")
    int queryContentTotal();

    /**
     * 查询某条资讯要推送的总用户数量
     * @return
     */
    @Select("SELECT COUNT(*) from pushlist where con_id=#{con_id}")
    int queryTotalByConId(int con_id);
    /**
     * 查询谋篇资讯要推送的所有用户
     */
    @Select("select * from pushlist where con_id=#{con_id} limit #{start},#{limit}")
    List<PushList> queryAllUserByConId(@Param("con_id")int con_id,@Param("start")int start,@Param("limit")int limit);

    /**
     * 判断某篇内容是否已经进入了退送列表
     * @param con_id
     * @param uid
     * @return
     */
    @Select("select count(*) from pushlist where con_id=#{con_id} and uid=#{uid}")
    public int judgeUidComePushList(@Param("con_id") int con_id,@Param("uid") int uid);

}
